<div class="uk-clearfix list-header">
  <h4 class="tm-article-subtitle uk-float-left"> 管理员管理</h4>

  <div class="uk-float-right">
    <%= link_to new_backend_admin_user_path, class: 'uk-button uk-button-success' do %>
      <i class="uk-icon-plus"></i> 新增
    <% end %>
  </div>
</div>
<hr>
<div class="list-search uk-form">
  <%= search_form_for @search, url: backend_admin_users_path, html: {class: 'form'} do |f| %>
    <%= f.text_field :name_cont, placeholder: '填写姓名' %>
    <%= f.text_field :email_cont, placeholder: '填写邮箱' %>
    <label class="uk-form-label"> 状态 </label>
    <%= f.select :status_eq, @admin_users.options_for_enum_select(:statuses, raw: true), include_blank: '全部状态' %>
    <button class="uk-button">搜索</button>
  <% end %>
</div>

<div class="uk-margin-top list-body">
  <div class="uk-overflow-container thin-scroll" style="min-height: calc(100vh - 220px);max-height:calc(100vh - 220px); ">
    <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed  horizontal-scroll" border="1">
      <thead>
      <tr>
        <th>登录名</th>
        <th>姓名</th>
        <th>邮箱</th>
        <th>角色</th>
        <th>状态</th>
        <th>操作</th>
      </tr>
      </thead>
      <tbody>
      <% @admin_users.each do |administrator| %>
        <tr>
          <td><%= administrator.login %></td>
          <td><%= administrator.name %></td>
          <td><%= administrator.email %></td>
          <!--          <td><%#= administrator.try(:role).try(:name) %></td>-->
          <td data-uk-tooltip title="<%=administrator.roles_names%>"><%= administrator.roles.length %></td>
          <td>
            <% if administrator.id == 1 %>
              <a href="#" class="uk-button uk-button-mini">
                不能禁用超级管理员
                <i class="uk-icon-user"></i>
              </a>
            <% elsif administrator == current_admin %>
              <a href="#" class="uk-button uk-button-mini">
                不能禁用当前管理员
                <i class="uk-icon-user"></i>
              </a>
            <% else %>
              <%= link_to switch_backend_admin_user_path(administrator), method: :put, data: {confirm: "确认#{administrator.active? ? '锁定' : '启用'}该管理员吗？"}, class: "uk-button uk-button-mini #{'uk-button-primary' if administrator.active?}" do %>
                <i class="<%= administrator.active? ? 'uk-icon-unlock' : 'uk-icon-lock' %>"></i>
                <%= administrator.enum_name(:status) %>
              <% end %>
            <% end %>
          </td>
          <td>
            <%= link_to edit_backend_admin_user_path(administrator), class: 'uk-button uk-button-mini uk-button-primary' do %>
              <i class="uk-icon-edit"></i> 修改
            <% end %>
            <% if administrator.id != 1 && administrator != current_admin %>
              <%= link_to backend_admin_users_path(administrator), method: :delete, data: {confirm: '确认删除该管理员吗？'}, class: 'uk-button uk-button-mini uk-button-danger' do %>
                <i class="uk-icon-trash"></i> 删除
              <% end %>
            <% end %>
          </td>
        </tr>
      <% end %>
      </tbody>
    </table>
    <div class="paginate-info uk-clearfix uk-margin-bottom">
      <div class="uk-float-left">
        <%= paginate_info(@admin_users) %>
      </div>
      <div class="uk-float-right">
        <%= paginate @admin_users, theme: 'admin' %>
      </div>
    </div>

  </div>
</div>
